#include <REGX52.H>
#include "Delay.h"
#include "LCD1602.h"
#include "Nixie.h"
#include "Matrix.h"

#define PASSWORD 2345

void passwordLock()
{
	unsigned char keyNumber = 0;
	int count = 0, password = 0;
	//初始化
	LCD_Init();
	LCD_ShowString(1, 1, "Password:");
	LCD_ShowNum(2, 1, 0, 4);
	while(1)
	{
		keyNumber = matrixKey();
		//规定S1~S9为1~9，S10为0
		if(keyNumber != 0)
		{
			//小于等于10为输入数字
			if(keyNumber <= 10)
			{	
				if(count < 4)
				{
					password *= 10;
					password += (keyNumber % 10);
					LCD_ShowNum(2, 1, password, 4);
					count++;
				}
			}
			else if(keyNumber == 11)//确认键
			{
				if(password == PASSWORD)
					LCD_ShowString(1, 14, "OK ");
				else
					LCD_ShowString(1, 14, "ERR");
				password = 0;
				count = 0;
				LCD_ShowNum(2, 1, password, 4);
			}
			else if(keyNumber == 12)//取消键
			{
				password = 0;
				count = 0;
				LCD_ShowNum(2, 1, password, 4);
			}
		}
		
	}
}
	
int main()
{
	passwordLock();
	return 0;
}